/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.concurrent.locks.ReentrantLock;

/**
 *
 * @author Gautier
 */
public class SerializeInput implements Runnable {

    private ArrayList a;
     private final ReentrantLock lock = new ReentrantLock();
    public SerializeInput(ArrayList al) {
        this.a = al;
    }

    @Override
    public void run() {
        FileInputStream fichier = null;
        lock.lock();
        try {
            fichier = new FileInputStream("contacts.ser");
            ObjectInputStream ois = new ObjectInputStream(fichier);
            ArrayList al;
            al = (ArrayList<Contact>) ois.readObject();
            a.removeAll(a);
            a.addAll(al);

        } catch (Exception ex) {
            System.out.println("Error in input");
        } finally{
            lock.unlock();
        }
    }

}
